import Util.WindowsUtil as util


class WidgetConfig:
    """
        控件属性类
        使用了发布订阅模式，可以动态更改控件的某些属性
    """

    def __init__(self, color: str, Ctrl, text="", font= "未知字体"):
        self.Ctrl = Ctrl
        self.text = text
        self.color = color
        self.font = font

        self.Color = self.color
        self.Text = self.text

    def __str__(self):
        return self.Color

    def initFont(self):
        self.Font = self.font

    def getWidget(self):
        return self.Ctrl

    @property
    def Text(self):
        return self.text

    @Text.setter
    def Text(self, param):
        self.text = param
        self.Ctrl["text"] = param

    @property
    def Color(self):
        return self.color

    @Color.setter
    def Color(self, param):
        self.color = param
        self.Ctrl.config(bg=param)

    @property
    def Font(self):
        return self.font

    @Font.setter
    def Font(self, value):
        self._Font = value
        self.Ctrl.config(font=util.Font(self.Ctrl).Default if self.Font == util.Status.UnkownFont else self.Font)
